package org.ssp.util;

import net.sf.json.JSONObject;

/*
 * 二维码
 */
public class BindCodeUtil {
	public final static String TICKET_URL="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN";
	public final static String BINDCODE_URL="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET";

	public static String requestTicket(String json,String access_token){
		String result=null; 
		String url=TICKET_URL.replace("TOKEN", access_token);
		String str = null;
		try {
			str = CommonUtil.httpsRequest(url, "POST", json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//			通过json-lib的API把json字符串转化成java对象
			JSONObject jsonObject=JSONObject.fromObject(str);
			if(null!=jsonObject){
				result=jsonObject.getString("ticket");
			}
			return result;
	}
	
	public static String BindCode(String ticket){
		String result=null; 
		String url=BINDCODE_URL.replace("TICKET", ticket);
		String str = null;
		try {
			str = CommonUtil.httpsRequest(url, "GET", null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}


}
